package com.qf.test;

import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;


import java.io.InputStream;
import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.test
 * @Description:
 * @Date 2022/6/12 16:27
 */
public class test {
    @Test
    public void name() throws  Exception{
        /**
         * 读取配置文件
         */
        String str="mybatis-config.xml";
        InputStream is= Resources.getResourceAsStream(str);
        //2. 创建会话工厂sqlSessionFactory
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
        //3. 通过工厂创建会话SqlSession对象
        SqlSession sqlSession = build.openSession();
        //4. 获取Mapper实例化对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用方法
        List<User> user = mapper.findUser();
        System.out.println(user);


    }
}
